<?php

namespace App\Service\Activity;

use App\Helpers\AliyunUtil;
use App\Helpers\ConfigUtil;
use App\Model\DailyTaskLog;
use App\Model\UserProfile;
use App\Service\BaseService;

/**
 * 每日有奖
 */
class DailyActService extends BaseService
{
    public function handle()
    {
        $userId = $this->getUserId();
        $platform = $this->request->input('platform', 1);
        $profile = UserProfile::getProfile($userId);
        $role = UserProfile::checkRoleHost($profile->role) ? 'host' : 'user';

        if ($profile->gender == 0 && $profile->avatar_vrfy == 1) {
            $role = 'host';
        }

        if ($platform == 1) return ['list' => []];
        // if (!DailyTaskLog::showLimit($userId)) {
        //     $ret['list'] = [];
        //     return $ret;
        // }
        $ret['list'] = array_values(ConfigUtil::getDailyTasks($role));
        $text = ['去完成', '可领取', '已领取'];
        $taskIds = DailyTaskLog::checkToday($userId);
        foreach ($ret['list'] as $k => &$item) {
            $status = !isset($taskIds[$item['id']]) ? DailyTaskLog::STATUS_UNDO : $taskIds[$item['id']];
            $item['buttong_text'] = $text[$status];
            //0-去完成, 1-可领取, 2-已领取
            $item['buttong_status'] = $status;
            //icon的角标值
            $item['icon'] = AliyunUtil::IMG_HOST_V2 . $item['icon'];
        }
        return $ret;
    }
}
